package org.metasketch.editor.project;

import org.metasketch.demo.project.DEMOProject;
import org.metasketch.demo.project.DEMOProjectHandler;
import org.metasketch.editor.IProjectHandler;
import org.metasketch.editor.Project;
import org.metasketch.ham.project.HAMProject;
import org.metasketch.ham.project.HAMProjectHandler;

public class MultipleProjectHandler implements IProjectHandler {

	DEMOProjectHandler demoProjectHandler = new DEMOProjectHandler();
	HAMProjectHandler hamProjectHandler = new HAMProjectHandler();

	@Override
	public Project newProject() throws Throwable {
		MultipleProject project = new MultipleProject();
		return project;
	}

	@Override
	public void saveProject(Project project) throws Throwable {
		MultipleProject mProject = (MultipleProject) project;
		demoProjectHandler.saveProject(mProject.getDemoProject());
		hamProjectHandler.saveProject(mProject.getHamProject());

	}

	@Override
	public Project loadProject(String path) throws Throwable {
		MultipleProject project = new MultipleProject();

		Project demoProject = demoProjectHandler.loadProject(path);
		Project hamProject = hamProjectHandler.loadProject(path);

		project.setDemoProject((DEMOProject) demoProject);
		project.setHamProject((HAMProject) hamProject);

		project.setPath(path);
		// project.setDirty(true);

		return project;

	}

}
